package com.ck.ips.controller;

import com.ck.common.model.OperationResult;
import com.ck.core.constant.DictionaryTypeEnum;
import com.ck.core.constant.SysConfigNameEnum;
import com.ck.ips.service.DeviceService;
import com.ck.ips.service.program.ScreenCanvasMappingService;
import com.ck.ips.service.sys.DictionaryService;
import com.ck.ips.service.sys.SysConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
* @Description: 全局配置controller
* @Author: hf
* @Date:    2019/4/29 9:43
* @Version: 1.0
*/
@RestController
public class GlobalConfigController extends BaseController{
    private static Logger logger = LoggerFactory.getLogger(GlobalConfigController.class);

    @Autowired
    private SysConfigService sysConfigService;
    @Autowired
    private DictionaryService dictionaryService;
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private ScreenCanvasMappingService screenCanvasMappingService;

    /**
     * 登录
     */
    @PostMapping("/globalconfig")
    public OperationResult globalConfig() {
        Map<String,Object> config = new HashMap<>();
        config.put(SysConfigNameEnum.LOGO_URL.getType(),sysConfigService.getByType(SysConfigNameEnum.LOGO_URL));
        config.put(SysConfigNameEnum.PLATFORM_NAME.getType(),sysConfigService.getByType(SysConfigNameEnum.PLATFORM_NAME));
        //设备类型
        config.put("deviceType",dictionaryService.listByType(DictionaryTypeEnum.DEVICE_TYPE.getType()));
        //分辨率
        config.put("resolution",deviceService.getDistinctResolvingPowerByDeviceCodes(null, null) );
        //节目来源
        config.put("programOrigin",dictionaryService.listByType(DictionaryTypeEnum.PROGRAM_ORIGIN.getType()));
        //节目状态
        config.put("programStatus",dictionaryService.listByType(DictionaryTypeEnum.PROGRAM_STATUS.getType()));
        //节目投放级别
        config.put("programLevel",dictionaryService.listByType(DictionaryTypeEnum.PROGRAM_PUTIN_LEVEL.getType()));
        //节目投放限制
        config.put("programLimit",dictionaryService.listByType(DictionaryTypeEnum.PROGRAM_PUTIN_LIMIT.getType()));
        //定时开关机是否区分节假日
        config.put("bootTimeDiff",sysConfigService.getByType(SysConfigNameEnum.BOOT_TIME_DIFF));
        //画布
        config.put("resolutionCanvasMapping", screenCanvasMappingService.getMappingForConfig());
        //是否需要审核
        config.put("needAuthProgram", sysConfigService.getByType(SysConfigNameEnum.NEED_AUTH_PROGRAM));
        return OperationResult.newSuccessOperationResult(config);
    }
    @GetMapping("/getAlarmConfig")
    public OperationResult getAlarmConfig() {
        Map<String, Object> config = new HashMap<>();
        //定时开关机是否区分节假日
        config.put("programOnlineAlarm", sysConfigService.getByType(SysConfigNameEnum.PROGRAM_ONLINE_ALARM));
        config.put("programOfflineAlarm", sysConfigService.getByType(SysConfigNameEnum.PROGRAM_OFFLINE_ALARM));
        return OperationResult.newSuccessOperationResult(config);
    }

}
